﻿using System;


namespace BizElements.BusinessLayer
{
    /// <summary>
    /// An implementation of <see cref="IMethodRemoter"/> which doesn't remote method calls.
    /// </summary>
    /// <remarks>Methods are invoked directly on the given object via reflection. No marshalling occurs.</remarks>
    public class DirectMethodCaller : IMethodRemoter
    {
        #region IMethodRemoter.

        /// <summary>Invokes the method via reflection in the same process and memory space from where the call originated. No marshalling occurs.</summary>
        /// <param name="obj">Object which supports the execution of the specified method. May be changed in the method.</param>
        /// <param name="methodName">Method which is to be invoked via reflection.</param>
        /// <param name="methodParameters">Method parameters.</param>
        /// <returns>Method's return value.</returns>
        public object InvokeMethod(object obj, string methodName, params object[] methodParameters)
        {
            return ReflectionUtil.InvokeMethod(obj, methodName, methodParameters);
        }

        /// <summary>Invokes the static method via reflection in the same process and memory space from where the call originated. No marshalling occurs.</summary>
        /// <param name="type">Type which contains the specified static method.</param>
        /// <param name="methodName">Method to be executed.</param>
        /// <param name="methodParameters">Method parameters.</param>
        /// <returns>Method's return value.</returns>
        public object InvokeStaticMethod(Type type, string methodName, params object[] methodParameters)
        {
            return ReflectionUtil.InvokeStaticMethod(type, methodName, methodParameters);
        }

        /// <summary>Invokes the generic method via reflection in the same process and memory space from where the call originated. No marshalling occurs.</summary>
        /// <param name="obj">Object which supports the execution of the specified method. May be changed in the method.</param>
        /// <param name="methodName">Generic method which is to be invoked via reflection.</param>
        /// <param name="methodParameters">Method parameters.</param>
        /// <returns>Method's return value.</returns>
        public object InvokeGenericMethod(object obj, string methodName, params object[] methodParameters)
        {
            return ReflectionUtil.InvokeGenericMethod(obj, methodName, methodParameters);
        }

        /// <summary>Invokes the generic static method via reflection in the same process and memory space from where the call originated. No marshalling occurs.</summary>
        /// <param name="type">Type which contains the specified static method.</param>
        /// <param name="methodName">Generic method to be executed.</param>
        /// <param name="methodParameters">Method parameters.</param>
        /// <returns>Method's return value.</returns>
        public object InvokeGenericStaticMethod(Type type, string methodName, params object[] methodParameters)
        {
            return ReflectionUtil.InvokeGenericStaticMethod(type, methodName, methodParameters);
        }

        /// <summary>
        /// Has no meaning. Methods are executed locally.
        /// </summary>
        public string Url
        {
            get { return null; }
            set { }
        }

        /// <summary>
        /// Returns <b>false</b> indicating that methods are invoked directly on the given object. No remoting occurs.
        /// </summary>
        public bool ImplementsRemoting
        {
            get { return false; }
        }

        #endregion
    }
}